package com.ruoyi.system.controller;

import com.alibaba.fastjson.JSON;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.security.utils.SecurityUtils;
import com.ruoyi.system.domain.SysCollect;
import com.ruoyi.system.domain.SysFollow;
import com.ruoyi.system.domain.SysVideo;
import com.ruoyi.system.service.BehaviorService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@RequestMapping("/behavior")
public class BehaviorController {

    @Autowired
    private BehaviorService behaviorService;

    /**
     * 点赞
     */
    @PostMapping("/likes")
    public AjaxResult likesBehavior(@RequestBody Map<String, Object> dto)
    {
        boolean operation = (boolean)dto.get("operation");
        SysVideo sysVideo = JSON.parseObject(JSON.toJSONString(dto.get("SysVideo")), SysVideo.class);
        return behaviorService.likesBehavior(sysVideo, SecurityUtils.getUserId(), operation);
    }

    /**
     * 收藏
     */
    @PostMapping("/collect")
    public AjaxResult collectBehavior(@RequestBody Map<String, Object> dto)
    {
        boolean operation = (boolean)dto.get("operation");
        SysCollect sysCollect = JSON.parseObject(JSON.toJSONString(dto.get("SysCollect")), SysCollect.class);
        return behaviorService.collectBehavior(sysCollect, SecurityUtils.getUserId(), operation);
    }

    @PostMapping("/follow")
    public AjaxResult followBehavior(@RequestBody Map<String, Object> dto)
    {
        boolean operation = (boolean)dto.get("operation");
        SysFollow sysFollow = JSON.parseObject(JSON.toJSONString(dto.get("SysFollow")), SysFollow.class);
        return behaviorService.followehavior(sysFollow, SecurityUtils.getUserId(), operation);
    }

    /**
     * 加载用户行为
     */
    @PostMapping("/load")
    public AjaxResult loadBehavior(@RequestBody Map<String, Object> map)
    {
        return behaviorService.loadBehavior(map);
    }
//    /**
//     * 阅读
//     */
//    @PostMapping("/read_behavior")
//    public AjaxResult readBehavior(@RequestBody ReadBehaviorDto dto)
//    {
//        return behaviorService.readBehavior(dto);
//    }
//
//    /**
//     * 不喜欢
//     */
//    @PostMapping("/un_likes_behavior")
//    public AjaxResult unLikesBehavior(@RequestBody UnLikesBehaviorDto dto)
//    {
//        return behaviorService.unLikesBehavior(dto);
//    }
}
